﻿CREATE VIEW [acms].[UnusedPostControl_View]
AS 
	SELECT 
		b.Id,
		a.Id as PostId, 
		c.Name, 
		b.Value, 
		d.AdminControlType,
		b.VersionId
	FROM [acms].[Posts] a 
		inner join [acms].[PostControls] b on a.Id = b.PostId
		inner join [acms].[TemplateControls] c on b.TemplateControlId = c.Id
		inner join [acms].[ControlTypes] d on c.TypeId = d.Id
	Where c.TemplateId <> a.TemplateId and c.Deleted = 0 and d.Deleted = 0
;